package com.jinlejia.erp.ui.mine.transfer;

import android.os.Bundle;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.style.AbsoluteSizeSpan;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.jinlejia.erp.R;
import com.jinlejia.erp.databinding.ActivityTransferInfomationBinding;

public class TransferInfomationActivity extends AppCompatActivity {

    private ActivityTransferInfomationBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_transfer_infomation);


        binding.backBtn.setOnClickListener(view -> finish());
        JSONObject object = JSON.parseObject(getIntent().getStringExtra("info"));
        //行政部门
        if (object.containsKey("oldDeptName") && !TextUtils.isEmpty(object.getString("oldDeptName"))) {
            binding.oldDepartment.setVisibility(View.VISIBLE);
            binding.oldDepartment.setText(object.getString("oldDeptName"));
        } else {
            binding.oldDepartment.setVisibility(View.GONE);
        }
        if (object.containsKey("newDeptName") && !TextUtils.isEmpty(object.getString("newDeptName"))) {
            binding.newDepartment.setVisibility(View.VISIBLE);
            binding.newDepartment.setText(object.getString("newDeptName"));
        } else {
            binding.newDepartment.setVisibility(View.GONE);
        }
        if (object.getString("oldDeptName").equals(object.getString("newDeptName"))) {
            binding.newDepartment.setVisibility(View.GONE);
        }
        if ((!object.containsKey("oldDeptName") || TextUtils.isEmpty(object.getString("oldDeptName")))
                && (!object.containsKey("newDeptName") || TextUtils.isEmpty(object.getString("newDeptName")))) {
            binding.layoutDepartment.setVisibility(View.GONE);
        }
        //直属上级
        if (object.containsKey("oldleaderName") && !TextUtils.isEmpty(object.getString("oldleaderName"))) {
            String leader = object.getString("oldleaderName").concat("\n").concat(object.getString("oldleaderDutyName"));
            SpannableString spanString = new SpannableString(leader);
            AbsoluteSizeSpan span = new AbsoluteSizeSpan(28);
            spanString.setSpan(span, object.getString("oldleaderName").length(), leader.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            binding.oldSuperior.setText(spanString);
        } else {
            binding.oldSuperior.setVisibility(View.GONE);
        }
        if (object.containsKey("newleaderName") && !TextUtils.isEmpty(object.getString("newleaderName"))) {
            String leader = object.getString("newleaderName").concat("\n").concat(object.getString("newleaderDutyName"));
            SpannableString spanString = new SpannableString(leader);
            AbsoluteSizeSpan span = new AbsoluteSizeSpan(28);
            spanString.setSpan(span, object.getString("newleaderName").length(), leader.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            binding.newSuperior.setText(spanString);
        } else {
            binding.newSuperior.setVisibility(View.GONE);
        }
        if (object.getString("oldleaderName").equals(object.getString("newleaderName"))) {
            binding.newSuperior.setVisibility(View.GONE);
        }
        if ((!object.containsKey("oldleaderName") || TextUtils.isEmpty(object.getString("oldleaderName")))
                && (!object.containsKey("newleaderName") || TextUtils.isEmpty(object.getString("newleaderName")))) {
            binding.layoutSuperior.setVisibility(View.GONE);
        }

        //职务
        if (object.containsKey("oldDutyName") && !TextUtils.isEmpty(object.getString("oldDutyName"))) {
            binding.oldJob.setText(object.getString("oldDutyName"));
        } else {
            binding.oldJob.setVisibility(View.GONE);
        }
        if (object.containsKey("newDutyName") && !TextUtils.isEmpty(object.getString("newDutyName"))) {
            binding.newJob.setText(object.getString("newDutyName"));
        } else {
            binding.newJob.setVisibility(View.GONE);
        }
        if (object.getString("oldDutyName").equals(object.getString("newDutyName"))) {
            binding.newJob.setVisibility(View.GONE);
        }
        if ((!object.containsKey("oldDutyName") || TextUtils.isEmpty(object.getString("oldDutyName")))
                && (!object.containsKey("newDutyName") || TextUtils.isEmpty(object.getString("newDutyName")))) {
            binding.layoutJob.setVisibility(View.GONE);
        }
        if ((object.containsKey("newTrainingFlag"))&&!TextUtils.isEmpty(object.getString("newTrainingFlag"))){
            binding.lineaTrainingLogo.setVisibility(View.VISIBLE);
            binding.oldTrainingLogo.setText(object.getString("oldTrainingFlag"));
            binding.newTrainingLogo.setText(object.getString("newTrainingFlag"));
        }else{
            binding.lineaTrainingLogo.setVisibility(View.GONE);
        }

        //门店
        if (object.containsKey("oldStoreName") && !TextUtils.isEmpty(object.getString("oldStoreName"))) {
            binding.oldStore.setText(object.getString("oldStoreName"));
        } else {
            binding.oldStore.setVisibility(View.GONE);
        }
        if (object.containsKey("newStoreName") && !TextUtils.isEmpty(object.getString("newStoreName"))) {
            binding.newStore.setText(object.getString("newStoreName"));
        } else {
            binding.newStore.setVisibility(View.GONE);
        }
        if (object.getString("oldStoreName").equals(object.getString("newStoreName"))) {
            binding.newStore.setVisibility(View.GONE);
        }
        if ((!object.containsKey("oldStoreName") || TextUtils.isEmpty(object.getString("oldStoreName")))
                && (!object.containsKey("newStoreName") || TextUtils.isEmpty(object.getString("newStoreName")))) {
            binding.layoutStore.setVisibility(View.GONE);
        }

        //共享店
        if (object.containsKey("oldshareStoreName") && !TextUtils.isEmpty(object.getString("oldshareStoreName"))) {
            binding.oldShareShop.setText(object.getString("oldshareStoreName"));
        } else {
            binding.oldShareShop.setVisibility(View.GONE);
        }
        if (object.containsKey("newshareStoreName") && !TextUtils.isEmpty(object.getString("newshareStoreName"))) {
            binding.newShareShop.setText(object.getString("newshareStoreName"));
        } else {
            binding.newShareShop.setVisibility(View.GONE);
        }
        if (object.getString("oldshareStoreName").equals(object.getString("newshareStoreName"))) {
            binding.newShareShop.setVisibility(View.GONE);
        }
        if ((!object.containsKey("oldshareStoreName") || TextUtils.isEmpty(object.getString("oldshareStoreName")))
                && (!object.containsKey("newshareStoreName") || TextUtils.isEmpty(object.getString("newshareStoreName")))) {
            binding.layoutShareShop.setVisibility(View.GONE);
        }

        if ((object.containsKey("recruitChannel") && !TextUtils.isEmpty(object.getString("recruitChannel")))) {
            binding.layoutRecruitmentChannels.setVisibility(View.VISIBLE);
            binding.tvRecruitmentChannels.setText(String.valueOf(object.get("recruitChannel")));
        }
        //其他
        if (object.containsKey("recruitInfo") || object.containsKey("transferType")) {
            String tmp = "";
            switch (Integer.parseInt(object.get("transferType").toString())) {
                case 0:
                    tmp = "下级人员转移:没有下级人员\n";
                    break;
                case 1:
                    tmp = "下级人员转移:转移给异动人异动前直属上级\n";
                    break;
                case 2:
                    tmp = "下级人员转移:跟随异动人转移\n";
                    break;
            }
            if (object.containsKey("recruitInfo")) {
                tmp.concat("招募人：").concat(object.getString("recruitInfo"));
            }
            binding.otherInfo.setText(tmp);
        } else {
            binding.otherInfo.setVisibility(View.GONE);
        }

    }

}
